package com.zxbit.flash.presenter;

import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.common.UserInfo;
import com.zxbit.flash.mvpview.WorkAuthMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.AuthInfoResponse;
import com.zxbit.flash.response.BlankResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class WorkAuthPresenter extends BasePresenter {
    private WorkAuthMvpView mvpView;

    public WorkAuthPresenter(WorkAuthMvpView mvpView) {
        this.mvpView = mvpView;
    }

    /**
     * 获取单位认证的认证详情
     */
    public void getWorkAuthInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", UserInfo.getShowUuid());
        List<String> authPageCode = new ArrayList<>();
        authPageCode.add("company_code");
        map.put("authPageCode", authPageCode);
        toSubScribe(req.getAuthInfoData(UserInfo.getToken(), ParamsFactory.getCommonParams(map)), new CustomConsumer<AuthInfoResponse>() {
            @Override
            public void call(AuthInfoResponse authInfoResponse) {
                mvpView.onGetDataNext(authInfoResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }


    public void saveAuthInfo(Map<String, Object> map) {
        map.put("userUuid", UserInfo.getSaveUuid());
        map.put("authPageCode", "company_code");
        if (UserInfo.isUserInformationWrong())
            map.put("isInformationWrong", 1);
        toSubScribe(req.savePersonalAuth(UserInfo.getToken(), ParamsFactory.getCommonParams(map)), new CustomConsumer<BlankResponse>() {
            @Override
            public void call(BlankResponse response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
